#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

int parse_sequence_id(char* str)
{
    int pos;
    int len = strlen(str);
    for(pos = 0; pos < len; pos++){
        if(str[pos] == '.') break;
    }

    if(pos == len) {
        printf("[error] there's no dot in string!\n");
        return -1;
    }

    char seq_id[10] = {0};
    memcpy(seq_id,str,pos);
    

    return atoi(seq_id);
}

int find_dot_in_string(char* str)
{
    int pos;
    int len = strlen(str);
    for(pos = 0; pos < len; pos++){
        if(str[pos] == '.') break;
    }

    if(pos == len) {
        printf("[error] there's no dot in string!\n");
        pos = -1;
    }

    return pos;
}

int find_max_seqID(char* filePath)
{
    FILE* fp = fopen(filePath,"r+");

    char buf[4096] = {0};
    int max_id = 1;
    while(NULL != fgets(buf,sizeof(buf),fp)){
        // printf("%s",buf);
        if(buf[0] >= '0' && buf[0] <= '9'){
            max_id = parse_sequence_id(buf);
            // printf("id:%d\n",max_id);
        }

        memset(buf,0,sizeof(buf));
    }

    fclose(fp);
    return max_id;
}

int main()
{
    int id = find_max_seqID("/home/xulf/workspace/xulf/just-doit-source-code/justDoIt-pub/study_record/sentence_tmp.txt");

    return 0;
}